package com.xinghou.platform.dao.main.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.xinghou.platform.dao.bases.JdbcTemplate;
import com.xinghou.platform.dao.bases.database.CustomerContextHolder;
import com.xinghou.platform.model.main.OauthBind;

@Repository
public class OauthBindDAOImpl  {/*
	*//**
	 * @author liuwei.wen
	 *
	 *//*
	@Resource
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public OauthBind getOauthBindById(Integer Id) throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "select * from oauth_bind where Id = ?";
		OauthBind oauthBind = jdbcTemplate.queryForObject(sql, new Object[] { Id }, new OauthBindMapper());
		CustomerContextHolder.clearCustomerType();
		return oauthBind;
	}

	@Override
	public int updateOauthBind(OauthBind oauthBind) throws DataAccessException {
		StringBuffer strSQL = new StringBuffer("UPDATE oauth_bind set User_id = ?, Auth_type = ?, Auth_id = ?, Nick_name = ?, Access_token = ?,")
		.append("Access_token_secret = ?, STATUS = ?, Create_time = ?, Update_time = ? where Id=?");
		Object[] params = {oauthBind.getUserId(), oauthBind.getAuthType(), oauthBind.getAuthId(), oauthBind.getNickName(), oauthBind.getAccessToken(), 
				oauthBind.getAccessTokenSecret(), oauthBind.getStatus(), oauthBind.getCreateTime(), oauthBind.getUpdateTime(), oauthBind.getId()
		};
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret = jdbcTemplate.update(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}

	@Override
	public int saveOauthBind(OauthBind oauthBind) throws DataAccessException {
		StringBuffer strSQL = new StringBuffer
				("INSERT INTO oauth_bind(User_id,Auth_type,Auth_id,Nick_name,Access_token,Access_token_secret,STATUS,Create_time)values(?,?,?,?,?,?,?,?)"
			
				);
        Object[] params = {oauthBind.getUserId(), oauthBind.getAuthType(), oauthBind.getAuthId(), oauthBind.getNickName(), oauthBind.getAccessToken(), 
        oauthBind.getAccessTokenSecret(), oauthBind.getStatus(), oauthBind.getCreateTime()
          };
        CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_WRITE);
		int ret=jdbcTemplate.save(strSQL.toString(),params);
		CustomerContextHolder.clearCustomerType();
		return ret;
	}
	

	@Override
	public OauthBind getOauthBindByType(String type, String info)throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "select * from oauth_bind where Auth_type = ? AND Auth_id= ? ";
		OauthBind oauthBind = jdbcTemplate.queryForObject(sql, new Object[] { type,info }, new OauthBindMapper());
		CustomerContextHolder.clearCustomerType();
		return oauthBind;
	}

	@Override
	public ArrayList<OauthBind> getOauthBindByUserId(Integer userid)
			throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "select * from oauth_bind where User_id = ?";
		ArrayList<OauthBind> list = (ArrayList<OauthBind>)jdbcTemplate.query(sql, new Object[] { userid }, new OauthBindMapper());
		CustomerContextHolder.clearCustomerType();
		return list;
	}



	private static final class OauthBindMapper implements RowMapper<OauthBind> {
		public OauthBind mapRow(ResultSet rs, int rowNum) throws SQLException {
			OauthBind oauthBind = new OauthBind();
			oauthBind.setAccessToken(rs.getString("Access_token"));
			oauthBind.setAccessTokenSecret(rs.getString("Access_token_secret"));
			oauthBind.setAuthId(rs.getString("Auth_id"));
			oauthBind.setAuthType(rs.getString("Auth_type"));
			oauthBind.setCreateTime(rs.getTimestamp("Create_time"));
			oauthBind.setId(rs.getInt("Id"));
			oauthBind.setNickName(rs.getString("Nick_name"));
			oauthBind.setStatus(rs.getShort("STATUS"));
			oauthBind.setUpdateTime(rs.getTimestamp("Update_time"));
			oauthBind.setUserId(rs.getInt("User_id"));
			return oauthBind;
		}
	}



	@Override
	public OauthBind getOauthBindByTypeAndUserId(String type, int userid)
			throws DataAccessException {
		CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_READ);
		String sql = "select * from oauth_bind where Auth_type = ? AND User_id= ? ";
		OauthBind oauthBind = jdbcTemplate.queryForObject(sql, new Object[] { type,userid }, new OauthBindMapper());
		CustomerContextHolder.clearCustomerType();
		return oauthBind;
	}*/

}
